package com.google.zxing.rsa;

import com.google.zxing.client.BarcodeUtils;

import android.util.Log;

/** */
/**
 * 
 * @version 1.0
 * @since 1.0
 */
public class RSAUtils {
	 private static String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKfQchUIyJMK1DJXF6kpC3aous/leM2Vqf1s08NwVE2CzwySKBR4XF7X+uYR3+QiFEXF8NnCq4jDj1atA38v7MMCAwEAAQ==";

	public static boolean verify(byte[] barcodeData,byte[] sign) {
		try {
			byte[] decode = decode(sign);
			return BarcodeUtils.cmpBytes(barcodeData, decode)?true:false;

		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
//	public static byte[] encode(byte[] data){
//		try {
//			return   RSACoder.encryptByPrivateKey(data, privateKey);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return null;
//	}
	
	public static byte[] decode(byte[] data){
		try {
			return RSACoder.decryptByPublicKey(data, publicKey);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	public static byte[] toByteArray(int[] a) {
		byte[] b = new byte[a.length];
		for (int i = 0; i < a.length; i++) {
			b[i] = (byte) a[i];
		}
		return b;
	}
}
